package com.ithuameng.generator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class GeneratorApplicaton implements CommandLineRunner {

	@Autowired
	private CodeGenerator codeGenerator;

	public static void main(String[] args) throws Exception {
		SpringApplication.run(GeneratorApplicaton.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		List<String> list = new ArrayList<>();
		if (args.length > 0) {
			for (String arg : args) {
				if (arg.startsWith("--")) {
					continue;
				}
				list.add(arg);
			}
		}
		if (list.size() == 0) {
			System.err.println("请输入参数！");
			return;
		}
		for (String tableName : list) {
			codeGenerator.generator(tableName);
		}
	}
}